package com.gitee.loyo.config.properties;

import com.gitee.loyo.err.CoordinationFailureException;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author: Forward Seen
 * @description: 对接方配置
 * @createTime: 2024/4/23 14:55
 * @since: 1.0
 */
@Data
@ConfigurationProperties(prefix = ChargeProperties.PREFIX)
public class ChargeProperties {
    public static final String PREFIX = "charge";

    private String contextPath = "**/evcs/v1/{operatorKey}/**";

    private String contextPathMatch = "operatorKey";

    private Map<String, ChargeCoordinationProperty> collaborators = new LinkedHashMap<>();

    public ChargeCoordinationProperty getCoordinationProperty(String operatorKey) {
        return collaborators.get(operatorKey);
    }

    public ChargeNotifyProperty getNotifyProperty(String operatorKey) {
        ChargeCoordinationProperty p = collaborators.get(operatorKey);
        if (p == null) {
            throw new CoordinationFailureException("找不到对接方" + operatorKey + "的配置");
        }
        return p.getNotify();
    }

    public ChargeQueryProperty getQueryProperty(String operatorKey) {
        ChargeCoordinationProperty p = collaborators.get(operatorKey);
        if (p == null) {
            throw new CoordinationFailureException("找不到对接方" + operatorKey + "的配置");
        }
        return p.getQuery();
    }

    public Set<String> getOperatorKeys() {
        return collaborators.keySet();
    }
}
